function [value] = get_value(data, depth, time_obs, pos);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RETURNS THE SURFACE OR BOTTOM VALUE OF A PROFILE FOR A SINGLE DATE
% THIS ROUTINE ASSUME THAT THE DATASET COMPRISES ONE PROFILE PER SAMPLING 
% DATE
%
% INPUT:  
%        - data     : profiles of AWQ weekly data (depth x date) 
%                     at a sinlge site 
%         -depth    : profile sampling depth
%        - time_obs : sampling date 
%        - pos      : string , either 's' (surface) or 'b' (bottom)
%              
% OUTPUT:
%        - value    : array of bottom or surface sample value
%        
% Author: Benedicte Pasquer, IMOS/eMII (http://imos.org.au/)
% email: benedicte.pasquer@utas.edu.au
% May 2013   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for nt = 1:length(time_obs)
        
        if ~isempty(data);
          switch pos
            case 's'
                value(nt) = data(1,nt);
            case 'b'
                [val,idx] = max(abs(depth(:,nt)));
                
                value(nt) = data(idx,nt);  
                
          end
        else
            value(nt)= NaN;
            
        end
end


